home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 23 / Macromedia xRes Versión 2.0 completa (Spain) / MF 23 Gr ficos.bin / xRes 2.0 SE / Access / XresACCESS_SE.Dxr / 00004_New Menu Scripts.ls < prev    next >
Encoding:
Text File  |  1996-04-05  |  16.2 KB  |  459 lines

  1. global LevelList, anchorList, JumpList
  2.  
  3. on CreateAllMenus
  4.   set theOriginalTextList to ["Installation.txt", "1st Look.txt", "Source & Center.txt", "Explore.txt", "Inspiration.txt"]
  5.   set theStrippedTextList to ["README1 text stripped", "README2 text stripped", "README3 text stripped", "README4 text stripped", "README5 text stripped"]
  6.   set StructuresList to ["Menu 1 List Structure", "Menu 2 List Structure", "Menu 3 List Structure", "Menu 4 List Structure", "Menu 5 List Structure"]
  7.   set anchorList to [:]
  8.   set JumpList to [:]
  9.   repeat with i = 1 to count(theOriginalTextList)
  10.     set LevelList to [i]
  11.     set theOriginalCastText to getFileText(getAt(theOriginalTextList, i))
  12.     if theOriginalCastText = -1 then
  13.       alert("Could not read the last file... aborting file parsing.")
  14.       exit repeat
  15.     end if
  16.     set theDestination to getAt(StructuresList, i)
  17.     set DestString to word 1 to 2 of theDestination
  18.     set StrippedTextCast to the number of member (getAt(theStrippedTextList, i) & ".1")
  19.     put "Beginning to parse: " & DestString
  20.     put "File size: " & the number of chars in theOriginalCastText & " characters"
  21.     set theNewMenu to CreateMainMenu(theOriginalCastText, StrippedTextCast)
  22.     set the text of cast theDestination to string(theNewMenu)
  23.     put "Stripping control characters from " & DestString & "..."
  24.     set tempText to stripControlChars(theOriginalCastText)
  25.     set kLimit to 32 * 1024
  26.     repeat with j = 1 to 6
  27.       set castOffset to j - 1
  28.       set theCastNum to StrippedTextCast + castOffset
  29.       set firstChar to (kLimit * castOffset) + 1
  30.       set lastChar to kLimit * j
  31.       set the text of cast theCastNum to char firstChar to lastChar of tempText
  32.     end repeat
  33.     set theOriginalCastText to EMPTY
  34.     set tempText to EMPTY
  35.   end repeat
  36.   put "... writing out list of hypertext anchors..."
  37.   put anchorList into field "Anchor List"
  38.   put "... writing out list of hypertext jumps..."
  39.   put JumpList into field "Jump List"
  40.   put "Done compiling menus!"
  41. end
  42.  
  43. on getFileText suggestedName
  44.   set myFileio to new(xtra("fileio"))
  45.   openFile(myFileio, the pathName & "text files:" & suggestedName, 1)
  46.   if status(myFileio) <> 0 then
  47.     alert("I was unable to find the '" & suggestedName & "' text file. Click OK then find that text file in the next dialog box.")
  48.     set aFile to displayOpen(myFileio)
  49.     openFile(myFileio, aFile, 1)
  50.   end if
  51.   if status(myFileio) <> 0 then
  52.     alert("Unable to read the file successfully!")
  53.     set myFileio to 0
  54.     return -1
  55.   end if
  56.   set theFileText to readFile(myFileio)
  57.   set myFileio to 0
  58.   return theFileText
  59. end
  60.  
  61. on CreateMainMenu theText, aStrippedCastNum
  62.   set theCastNum to aStrippedCastNum
  63.   append(LevelList, 0)
  64.   set theMenu to doCreateMainMenu(theText, 1, 1, theCastNum)
  65.   return theMenu
  66. end
  67.  
  68. on doCreateMainMenu aBigTextBlock, currentLevel, currentLine, theStrippedCastNum
  69.   set newMenuList to []
  70.   set newMenu to [:]
  71.   set newPageList to []
  72.   set newPage to [:]
  73.   set pageCounter to 0
  74.   set thisPageImage to EMPTY
  75.   set thisPageMovie to EMPTY
  76.   set lastInterestingLine to 0
  77.   set maxLines to the number of lines in aBigTextBlock
  78.   set TenPercentLines to maxLines / 10
  79.   cursor(4)
  80.   repeat while currentLine <= maxLines
  81.     set theLine to line currentLine of aBigTextBlock
  82.     if theLine contains "{" & currentLevel & "}" then
  83.       set newMenuList to finishMenuLevel(newMenu, newPage, newPageList, newMenuList)
  84.       set newMenu to [:]
  85.       set newPageList to []
  86.       set newPage to [:]
  87.       set lastOne to count(LevelList)
  88.       setAt(LevelList, lastOne, getAt(LevelList, lastOne) + 1)
  89.       set thisHeader to stripChars(theLine, "{", "}")
  90.       set tempStr to EMPTY
  91.       repeat with i = 1 to currentLevel * 3
  92.         put " " after tempStr
  93.       end repeat
  94.       set thisHeader to tempStr & thisHeader
  95.       put thisHeader after tempStr
  96.       addProp(newMenu, #MenuHeading, thisHeader)
  97.       set pageCounter to 0
  98.       set lastInterestingLine to currentLine
  99.     end if
  100.     if theLine contains "{" & currentLevel + 1 & "}" then
  101.       set tempHeader to getProp(newMenu, #MenuHeading)
  102.       set theCharLoc to (currentLevel * 3) - 2
  103.       put "+" into char theCharLoc to theCharLoc + 1 of tempHeader
  104.       setProp(newMenu, #MenuHeading, tempHeader)
  105.       append(LevelList, 0)
  106.       set subMenuAndLines to doCreateMainMenu(aBigTextBlock, currentLevel + 1, currentLine, theStrippedCastNum)
  107.       set theSubMenu to getAt(subMenuAndLines, 1)
  108.       set newCurLine to getAt(subMenuAndLines, 2)
  109.       addProp(newMenu, #SubMenu, theSubMenu)
  110.       set currentLine to newCurLine - 1
  111.       set lastInterestingLine to currentLine
  112.     end if
  113.     set lev1 to "{" & currentLevel - 1 & "}"
  114.     set lev2 to "{" & currentLevel - 2 & "}"
  115.     set lev3 to "{" & currentLevel - 3 & "}"
  116.     if (theLine contains lev1) or (theLine contains lev2) or (theLine contains lev3) then
  117.       set newMenuList to finishMenuLevel(newMenu, newPage, newPageList, newMenuList)
  118.       deleteAt(LevelList, count(LevelList))
  119.       return [newMenuList, currentLine]
  120.     end if
  121.     if theLine contains "{a" then
  122.       set anchorOffset to offset("{a", theLine) + 2
  123.       set anchorEnd to offset("}", theLine)
  124.       set anchorNum to value(char anchorOffset to anchorEnd - 1 of theLine)
  125.       set tempLevelList to value(string(LevelList))
  126.       append(tempLevelList, pageCounter + 1)
  127.       addAnchorToList(anchorNum, tempLevelList)
  128.     end if
  129.     if theLine contains "{j" then
  130.       repeat while theLine contains "{j"
  131.         set jumpOffset to offset("{j", theLine) + 2
  132.         set jumpEnd to offset("}", theLine)
  133.         set jumpNum to value(char jumpOffset to jumpEnd - 1 of theLine)
  134.         repeat with wordCount = 1 to the number of words in theLine
  135.           if word wordCount of theLine contains "{j" then
  136.             set lastWordNum to wordCount - 1
  137.             repeat with hyperWords = lastWordNum down to 1
  138.               if word hyperWords of theLine starts "<" then
  139.                 set firstWordNum to hyperWords
  140.                 exit repeat
  141.               end if
  142.             end repeat
  143.           end if
  144.         end repeat
  145.         delete char jumpOffset - 2 to jumpEnd of theLine
  146.         set tempLevelList to value(string(LevelList))
  147.         append(tempLevelList, pageCounter + 1)
  148.         append(tempLevelList, currentLine - lastInterestingLine)
  149.         repeat with thisWord = firstWordNum to lastWordNum
  150.           append(tempLevelList, thisWord)
  151.           set hyperWord to word thisWord of theLine
  152.           if hyperWord contains "<" then
  153.             delete char offset("<", hyperWord) of hyperWord
  154.           end if
  155.           if hyperWord contains ">" then
  156.             delete char offset(">", hyperWord) of hyperWord
  157.           end if
  158.           addJumptoList(hyperWord, jumpNum, tempLevelList)
  159.           deleteAt(tempLevelList, count(tempLevelList))
  160.         end repeat
  161.       end repeat
  162.     end if
  163.     if (theLine contains "[image:") or (theLine contains "[zoomImage:") then
  164.       set imageOffset to offset("image:", theLine) + 6
  165.       set theSearchString to char imageOffset to length(theLine) of theLine
  166.       set imageList to returnThreeNamesList(theSearchString)
  167.       if theLine contains "[zoom" then
  168.         addProp(newPage, #zoomImage, imageList)
  169.       else
  170.         addProp(newPage, #pageImage, imageList)
  171.       end if
  172.       set lastInterestingLine to currentLine
  173.     end if
  174.     if theLine contains "[movie" then
  175.       set movieOffset to offset("[movie:", theLine) + 7
  176.       set theSearchString to char movieOffset to length(theLine) of theLine
  177.       set movieList to returnThreeNamesList(theSearchString)
  178.       set movieName to getAt(movieList, 2)
  179.       if (movieName contains ".dir") or (movieName contains ".dxr") then
  180.         addProp(newPage, #pageMovieInAWindow, movieList)
  181.       else
  182.         addProp(newPage, #pageMovie, movieList)
  183.       end if
  184.       set lastInterestingLine to currentLine
  185.     end if
  186.     if theLine contains "[launch:" then
  187.       set appOffset to offset("[launch:", theLine) + 8
  188.       set theSearchString to char appOffset to length(theLine) of theLine
  189.       set newLaunchList to returnThreeNamesList(theSearchString)
  190.       set the itemDelimiter to ","
  191.       set launchString to getAt(newLaunchList, 1)
  192.       set appName to item 1 of launchString
  193.       set MacDocName to item 2 of launchString
  194.       if MacDocName <> EMPTY then
  195.         set MacDocName to makeHeaderFlush(MacDocName)
  196.       end if
  197.       set secondEntry to getAt(newLaunchList, 2)
  198.       if secondEntry = launchString then
  199.         set WIN16DocName to MacDocName
  200.       else
  201.         set WIN16DocName to makeHeaderFlush(secondEntry)
  202.       end if
  203.       set thirdEntry to getAt(newLaunchList, 3)
  204.       if thirdEntry = secondEntry then
  205.         set WIN32DocName to WIN16DocName
  206.       else
  207.         set WIN32DocName to makeHeaderFlush(thirdEntry)
  208.       end if
  209.       set launchNames to appName & "," & MacDocName & "," & WIN16DocName & "," & WIN32DocName
  210.       if listp(getaProp(newPage, #PageLaunch)) then
  211.         append(getProp(newPage, #PageLaunch), launchNames)
  212.       else
  213.         addProp(newPage, #PageLaunch, [launchNames])
  214.       end if
  215.       set lastInterestingLine to currentLine
  216.     end if
  217.     if theLine contains "[application" then
  218.       set appOffset to offset("[application:", theLine) + 13
  219.       set theSearchString to char appOffset to length(theLine) of theLine
  220.       set appList to returnThreeNamesList(theSearchString)
  221.       addProp(newPage, #pageApp, appList)
  222.       set lastInterestingLine to currentLine
  223.     end if
  224.     if theLine contains "{p}" then
  225.       if lastInterestingLine < currentLine then
  226.         set StrippedTextCast to theStrippedCastNum
  227.         set PageText to string(lastInterestingLine + 1) && currentLine && StrippedTextCast
  228.         addProp(newPage, #PageText, PageText)
  229.       end if
  230.       set pageCounter to pageCounter + 1
  231.       set lastInterestingLine to currentLine
  232.       append(newPageList, newPage)
  233.       set newPage to [:]
  234.     end if
  235.     set currentLine to currentLine + 1
  236.     if TenPercentLines > 0 then
  237.       if (currentLine mod TenPercentLines) = 0 then
  238.         set percentDone to currentLine / TenPercentLines * 10
  239.         put string(percentDone) & "% complete..."
  240.       end if
  241.     end if
  242.   end repeat
  243.   if currentLevel > 1 then
  244.     set newMenuList to finishMenuLevel(newMenu, newPage, newPageList, newMenuList)
  245.     return [newMenuList, currentLine]
  246.   end if
  247.   set newMenuList to finishMenuLevel(newMenu, newPage, newPageList, newMenuList)
  248.   return newMenuList
  249.   cursor(0)
  250. end
  251.  
  252. on testParse theSearchString
  253.   set newLaunchList to returnThreeNamesList(theSearchString)
  254.   set the itemDelimiter to ","
  255.   set launchString to getAt(newLaunchList, 1)
  256.   set appName to item 1 of launchString
  257.   set MacDocName to item 2 of launchString
  258.   if MacDocName <> EMPTY then
  259.     set MacDocName to makeHeaderFlush(MacDocName)
  260.   end if
  261.   set secondEntry to getAt(newLaunchList, 2)
  262.   if secondEntry = launchString then
  263.     set WIN16DocName to MacDocName
  264.   else
  265.     set WIN16DocName to makeHeaderFlush(secondEntry)
  266.   end if
  267.   set thirdEntry to getAt(newLaunchList, 3)
  268.   if thirdEntry = secondEntry then
  269.     set WIN32DocName to WIN16DocName
  270.   else
  271.     set WIN32DocName to makeHeaderFlush(thirdEntry)
  272.   end if
  273.   set launchNames to appName & "," & MacDocName & "," & WIN16DocName & "," & WIN32DocName
  274.   put launchNames
  275. end
  276.  
  277. on returnThreeNamesList theSearchString
  278.   set theNameList to []
  279.   repeat with nameNum = 1 to 3
  280.     set nextNameList to getNextName(theSearchString)
  281.     set nextName to getAt(nextNameList, 1)
  282.     set theSearchString to getAt(nextNameList, 2)
  283.     append(theNameList, nextName)
  284.   end repeat
  285.   set MacName to getAt(theNameList, 1)
  286.   set WIN16Name to getAt(theNameList, 2)
  287.   if WIN16Name = EMPTY then
  288.     setAt(theNameList, 2, MacName)
  289.     setAt(theNameList, 3, MacName)
  290.   else
  291.     if getAt(theNameList, 3) = EMPTY then
  292.       setAt(theNameList, 3, WIN16Name)
  293.     end if
  294.   end if
  295.   return value(string(theNameList))
  296. end
  297.  
  298. on getNextName theLine
  299.   repeat with i = 1 to length(theLine)
  300.     if char i of theLine <> " " then
  301.       if theLine contains "/" then
  302.         set imageEnd to offset("/", theLine)
  303.       else
  304.         set imageEnd to offset("]", theLine)
  305.       end if
  306.       set imageName to char i to imageEnd - 1 of theLine
  307.       if imageName = "]" then
  308.         set imageName to EMPTY
  309.       end if
  310.       delete char 1 to imageEnd of theLine
  311.       return [imageName, theLine]
  312.       exit repeat
  313.     end if
  314.   end repeat
  315.   return [EMPTY, EMPTY]
  316. end
  317.  
  318. on finishMenuLevel aMenu, aPage, aPageList, aMenuList
  319.   if count(aMenu) > 0 then
  320.     if count(aPage) > 0 then
  321.       append(aPageList, aPage)
  322.     end if
  323.     addProp(aMenu, #PageList, aPageList)
  324.     append(aMenuList, aMenu)
  325.   end if
  326.   return aMenuList
  327. end
  328.  
  329. on addAnchorToList anchorNum, theList
  330.   set existsAlready to getaProp(anchorList, anchorNum)
  331.   if not voidp(existsAlready) then
  332.     alert("anchor " & anchorNum & " is defined multiple times!!")
  333.   else
  334.     addProp(anchorList, anchorNum, theList)
  335.   end if
  336. end
  337.  
  338. on addJumptoList theWord, jumpNum, theList
  339.   set existingWordList to getaProp(JumpList, theWord)
  340.   if not voidp(existingWordList) then
  341.     addProp(existingWordList, jumpNum, string(theList))
  342.     setProp(JumpList, theWord, existingWordList)
  343.   else
  344.     set newWordList to [:]
  345.     addProp(newWordList, jumpNum, string(theList))
  346.     addProp(JumpList, theWord, newWordList)
  347.   end if
  348. end
  349.  
  350. on stripChars whatText, startChar, endChar
  351.   set startAt to offset(startChar, whatText)
  352.   set endAt to offset(endChar, whatText)
  353.   set len to length(whatText)
  354.   set newString to EMPTY
  355.   if startAt > 1 then
  356.     set newString to char 1 to startAt - 1 of whatText
  357.   end if
  358.   if endAt < len then
  359.     put char endAt + 1 to len of whatText after newString
  360.   end if
  361.   return newString
  362. end
  363.  
  364. on getMenuDepth aHeading
  365.   set extraChar to EMPTY
  366.   repeat with i = 1 to length(aHeading)
  367.     set theChar to char i of aHeading
  368.     if theChar = "+" then
  369.       set extraChar to theChar
  370.     end if
  371.     if not (" +" contains theChar) then
  372.       return [(i + 1) / 3, extraChar]
  373.     end if
  374.   end repeat
  375. end
  376.  
  377. on makeHeaderFlush aHeading
  378.   set len to length(aHeading)
  379.   repeat with i = 1 to len
  380.     set theChar to char i of aHeading
  381.     if theChar = "+" then
  382.       set extraChar to theChar
  383.     end if
  384.     if not (" +" contains theChar) then
  385.       return char i to len of aHeading
  386.     end if
  387.   end repeat
  388. end
  389.  
  390. on stripReturnAtEnd theString
  391.   set theLineCount to the number of lines in theString
  392.   if line theLineCount of theString = EMPTY then
  393.     delete line theLineCount of theString
  394.   end if
  395.   return theString
  396. end
  397.  
  398. on getSpecificMenu aMenuHierarchy, theStartLevel, theMenuList
  399.   global theMenuString
  400.   set theMenuString to EMPTY
  401.   doGetSpecificMenu(aMenuHierarchy, theMenuList, theStartLevel, 1)
  402.   return stripReturnAtEnd(theMenuString)
  403. end
  404.  
  405. on doGetSpecificMenu aMenuHierarchy, theMenuList, theStartLevel, theLevel
  406.   global theMenuString
  407.   repeat with menuCounter = 1 to count(theMenuList)
  408.     set theMenu to getAt(theMenuList, menuCounter)
  409.     set theMenuName to getProp(theMenu, #MenuHeading)
  410.     if theLevel >= theStartLevel then
  411.       put theMenuName & RETURN after theMenuString
  412.     end if
  413.     if theLevel <= count(aMenuHierarchy) then
  414.       if menuCounter = getAt(aMenuHierarchy, theLevel) then
  415.         if listp(getaProp(theMenu, #SubMenu)) then
  416.           doGetSpecificMenu(aMenuHierarchy, getaProp(theMenu, #SubMenu), theStartLevel, theLevel + 1)
  417.         end if
  418.       end if
  419.     end if
  420.   end repeat
  421. end
  422.  
  423. on getAllMenus theMenuList
  424.   global theMenuString
  425.   set theMenuString to EMPTY
  426.   doGetMenu(theMenuList, 1, 99)
  427.   return stripReturnAtEnd(theMenuString)
  428. end
  429.  
  430. on getMenu theMenuList, stripCharsBool
  431.   global theMenuString
  432.   set theMenuString to EMPTY
  433.   doGetMenu(theMenuList, 1, 1)
  434.   if stripCharsBool then
  435.     repeat with i = 1 to the number of lines in theMenuString
  436.       if char 3 of line i of theMenuString = " " then
  437.         delete char 3 of line i of theMenuString
  438.       end if
  439.       delete char 1 to 2 of line i of theMenuString
  440.     end repeat
  441.   end if
  442.   return stripReturnAtEnd(theMenuString)
  443. end
  444.  
  445. on doGetMenu theMenuList, theLevel, howManyLevelsDeep
  446.   global theMenuString
  447.   set theCount to count(theMenuList)
  448.   if theCount > 0 then
  449.     repeat with menuCounter = 1 to theCount
  450.       set theMenu to getAt(theMenuList, menuCounter)
  451.       set theMenuName to getaProp(theMenu, #MenuHeading)
  452.       put theMenuName & RETURN after theMenuString
  453.       if listp(getaProp(theMenu, #SubMenu)) and (theLevel < howManyLevelsDeep) then
  454.         doGetMenu(getaProp(theMenu, #SubMenu), theLevel + 1, howManyLevelsDeep)
  455.       end if
  456.     end repeat
  457.   end if
  458. end
  459.